Ext.onReady(function() {
	var toolbar = Ext.create('Ext.toolbar.Toolbar', {
		dock : 'top',
		items : [ {
			text : '返回',
			xtype : 'button',
			listeners:{
				click: function(){
					location.href = "workMgr/flight_line_mgr";
				}
			}
		},{
			text : '刷新',
			xtype : 'button',
			listeners:{
				click: function(){
					window.location.reload();
				}
			}
		}]
	});
	
	var store = Ext.create('Ext.data.Store', {
	    fields:['Id', 'No', {name:"LongitudeDegrees",type:'float'}, 
	    {name:"LongitudeMinutes", type:'float'}, {
	    	name: 'LongitudeSeconds', type: 'float'
	    }, {
	    	name: "LatitudeDegrees", type: 'float'
	    }, {
	    	name: "LatitudeMinutes", type: 'float'
	    }, {
	    	name: "LatitudeSeconds", type: 'float'
	    }],
	    pageSize: 25,
	    autoLoad:true,
	    proxy: {
	        type: 'ajax',
	        url: '/tower_coordinate/'+flightLineId,
	        reader: {
	            type: 'json',
	            root: 'data.rows',
	            totalProperty: 'data.total'
	        }
	    }
	});
	var grid = Ext.create('Ext.grid.Panel', {
		id: "gtzb_grid",
		xtype: 'grouped-header-grid',
		store: store,
		margin: '5 5',
		listeners : {
			cellclick : function(self, td, cellIndex, record, tr, rowIndex, e,
					eOpts) {
				if (cellIndex == 7) {
					self.setLoading(true);
					
					if(e.target.nodeName == 'INPUT'){
						var LongitudeDegrees = record.get('LongitudeDegrees');
						var LatitudeDegrees = record.get('LatitudeDegrees');
						
						var tds = Ext.query("td", tr);
						var ldivs = Ext.query("div", tds[8]);
						var ladivs = Ext.query("div", tds[9]);
						if(e.target.checked){
							var LongitudeMinutes = record.get('LongitudeMinutes');
							var LongitudeSeconds = record.get('LongitudeSeconds');
							var LatitudeMinutes = record.get('LatitudeMinutes');
							var LatitudeSeconds = record.get('LatitudeSeconds');
							ldegree = LongitudeDegrees + LongitudeMinutes/60 + LongitudeSeconds/3600;
							ldivs[0].innerText = Number(ldegree).toFixed(8);
							ladegree = LatitudeDegrees + LatitudeMinutes/60 + LatitudeSeconds/3600;
							ladivs[0].innerText = Number(ladegree).toFixed(8);
						}
						else{
							ldivs[0].innerText = '';
							ladivs[0].innerText = '';
						}
					}
					self.setLoading(false);
				}
			}
		},
		columns : [ {
			text : '杆塔编号',
			dataIndex : 'No',
			width: 100
		}, {
			text : '经度',
			border: false,
			flex:1,
			columns:[{
				text: '(度)',
				dataIndex : 'LongitudeDegrees'
			},{
				text: '(分)',
				dataIndex : 'LongitudeMinutes'
			}, {
				text : '(秒)',
				dataIndex : 'LongitudeSeconds'
			}]
			
		}, {
			text : '纬度',
			flex:1,
			columns:[{
				text: '(度)',
				dataIndex : 'LatitudeDegrees'
			}, {
				text : '(分)',
				dataIndex : 'LatitudeMinutes'
			}, {
				text : '(秒)',
				dataIndex : 'LatitudeSeconds'
			}]
		},{
			text: '转换',
			renderer: function(v, meta, record){
				if(v){
					return '<input type="checkbox" checked="checked"/>';
				}
				else{
					return '<input type="checkbox"/>';
				}
			}
		},{
			text : '经度',
			columns:[{
				text: '(度)',
				width:200,
				renderer: function(v){
					return '';
				}
			}]
		}, {
			text : '纬度',
			columns:[{
				text: '(度)',
				width:200,
				renderer: function(v){
					return '';
				}
			}]
		},{
			text:'',
			flex:1
		}],
		bbar : Ext.create('Ext.PagingToolbar', {
							store : store,
							border: false,
							displayInfo : true,
							displayMsg : '显示{0} - {1} / 总数 {2}',
							emptyMsg : "没数据"
						})
	});
	
	var panel = Ext.create("Ext.panel.Panel", {
		title: '',
		border : false,
		bodyBorder : false,
		layout : 'fit',
		dockedItems : [ toolbar ],
		items : [ grid ]
	});
	Ext.create('Ext.Viewport', {
		layout : 'fit',
		style : 'background:none;background-color:white;',
		items : [ panel ]
	});
});